﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.ModelBinding;
using Kakaroto.Models;

namespace Kakaroto.Caixa
{
    public partial class Nota : System.Web.UI.Page
    {
        static string RawId = String.Empty;
        static string prevPage = String.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            CaixaActions ca = new CaixaActions();
            ca.EncerraCheckout();

            string subTotal = Request.QueryString["subTotal"];

            Pedido pedido = GetPedido();
            lblSubTotal.Text = String.Format("{0:0.##}", Convert.ToDouble(subTotal));
            lblServico.Text = String.Format("{0:0.##}", Convert.ToDouble(subTotal) * pedido.Servico/100);
            lblDesconto.Text = String.Format("{0:0.##}", Convert.ToDouble(subTotal) * pedido.Desconto / 100);
            lblRecebido.Text = String.Format("{0:0.##}", HttpContext.Current.Session["Quantia"]);
            lblTroco.Text = String.Format("{0:0.##}" , HttpContext.Current.Session["Troco"]);
            lblTotal.Text = String.Format("{0:0.##}", pedido.Total);
        }

        public Pedido GetPedido()
        {
            return HttpContext.Current.Session["Cx_Pedido"] as Pedido;
        }

        public IQueryable<ItemPedido> GetItensPedido()
        {
            Pedido pedido = GetPedido(); 
            KakarotoEntities _db = new KakarotoEntities();
            return _db.ItemPedido.Where(ip => ip.Id_Ped == pedido.Id);
        }

        protected void ImprimeBtn_Click(object sender, EventArgs e)
        {

        }

        protected void HomeBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("./Default.aspx");
        }
    }
}